package com.pro.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.pro.dao.SeatMapper;
import com.pro.domain.Seat;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
@Service
public class SeatServiceImpl implements SeatService {
    @Autowired
    private SeatMapper seatMapper;

    /*拿到该用户已经选的座位号集合*/
    @Override
    public List selectPosition(int timeid) {
        QueryWrapper<Seat> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("timeid",timeid);
        List<Seat> seats = seatMapper.selectList(queryWrapper);
        List positionList = new ArrayList();
        for (Seat seat : seats) {
            String position = seat.getPosition();
            positionList.add(position);
        }
        return positionList;
    }

    @Override
    public void insertPosition(int timeid, int memberid, String position) {
        Seat seat = new Seat();
        seat.setTimeid(timeid);
        seat.setMemberid(memberid);
        seat.setPosition(position);
        seatMapper.insert(seat);
    }

    @Override
    public void deletePosition(int timeid, int memberid,String position) {
        QueryWrapper<Seat> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("timeid",timeid);
        queryWrapper.eq("memberid",memberid);
        queryWrapper.eq("position",position);
        Seat seat = seatMapper.selectOne(queryWrapper);
        if(seat!=null){
            seatMapper.delete(queryWrapper);
        }else {
            System.out.println("不用删除");
        }
    }

    @Override
    public List selectPositionBymemberid(int timeid, int memberid) {
        QueryWrapper<Seat> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("timeid",timeid);
        queryWrapper.eq("memberid",memberid);
        List<Seat> seats = seatMapper.selectList(queryWrapper);
        List positionList = new ArrayList();
        for (Seat seat : seats) {
            String position = seat.getPosition();
            positionList.add(position);
        }
        return positionList;
    }
}
